package com.xiaozhichao.jarslink.main.controller;

import com.alibaba.fastjson.JSON;
import com.alipay.jarslink.api.*;
import com.google.common.collect.ImmutableList;
import com.xiaozhichao.jarslink.main.config.ModuleRefreshSchedulerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.net.URL;
import java.util.Iterator;
import java.util.List;

@Controller
@RequestMapping("jarslink")
public class HelloReaderController {

    @Autowired
    ModuleManager  manager;
    @Autowired
    ModuleLoader mduleLoader;

    @RequestMapping(value = "/index")
    @ResponseBody
    public String index(){
        return JSON.toJSONString(manager.getModules());
    }


    @RequestMapping(value = "/{moduleName}/{action}/{para}")
    @ResponseBody
    public String getModule(@PathVariable String moduleName, @PathVariable String action, @PathVariable String para){
        //查找模块
        Module moduleInstance = manager.find(moduleName);
        Object result = moduleInstance.doAction(action,para);
        return JSON.toJSONString(result);
    }


}
